package services

import (
	"mishop/models"
	"mishop/utils"
)

type IProductService interface {
	FindByID(product_id uint) (*models.Product, error)
	FindByCategoryID(page, rows int, category_id uint) (*models.Pages, error)
	Create(entity *models.Product) (*models.Product, error)
	Update(entity *models.Product) (*models.Product, error)
	Delete(product_id int) error
}
type ProductService struct {
	model models.IProduct
}

func (p *ProductService) Delete(product_id int) error {
	return p.model.Delete(product_id)
}

func (p *ProductService) Update(entity *models.Product) (*models.Product, error) {
	return p.model.Update(entity)
}

func (p *ProductService) Create(entity *models.Product) (*models.Product, error) {
	return p.model.Create(entity)
}

func (p *ProductService) FindByID(product_id uint) (*models.Product, error) {
	return p.model.FindByID(product_id)
}

func (p *ProductService) FindByCategoryID(page, rows int, category_id uint) (*models.Pages, error) {
	page,rows = utils.ProcessPagesEntity(page,rows)
	return p.model.FindByCategoryID(page, rows, category_id)
}

func NewProductService(model models.IProduct) IProductService {
	return &ProductService{model: model}
}
